<?php header('Content-Type: text/html; charset=iso-8859-1');
if (isset($_REQUEST['txtRecetaId']))
{	
	require_once($_SERVER['DOCUMENT_ROOT'].'/gourmet-express/trunk/src/class/mrp/recetas/FN/MrpRecetaFN.class.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'/gourmet-express/trunk/src/class/mrp/recetas/FN/MrpRecetaDetalleFN.class.php');
	
	$o_MrpRecetaFN = new MrpRecetaFN(); 
	
	$o_MrpRecetaFN->setRctRecetaId($_REQUEST['txtRecetaId']);
	
	$o_rptaH = $o_MrpRecetaFN->selectReceta_CabeceraDetalle();

?>  
<style>
	#moduleSection {
		margin:10 auto;
		width:98%;
		border-width: 1px; 
		border-style: solid; 
		border-color: #D0E8E8;
        position:relative;
        overflow:auto;  
	}
	#moduleSectionDetalleAdd {
		margin:5 auto;
		//background:#FFF;
		z-index:2;
		top :240px;
		padding:5px 5px 5px;
		position:absolute;
	}
    #moduleSectionDetalleAddList {
        margin:5 auto;
        //background:#FFF;
        z-index:20;
        top :100px;
        padding:10px 10px 10px;
        position:relative;
        height:300px;
    }
    .error {
    color: red;
    font-style: italic;
     }      
</style>
<script>
var CorrelaTivo=1;

add_TR_ItemCC = function ()
{
  CorrelaTivo = CorrelaTivo+1
  
  var id_ItemCode = "itemCode_"+CorrelaTivo;
  
   var sTr='';
	sTr+="<tr bgcolor='#FFFFFF'>";
	sTr+="<td ><input type='text' itemG='itemG' id='"+id_ItemCode+"' name='a_InsumoId["+CorrelaTivo+"]' size='15' style='width: 100px;' class='loadF2 required' ></td>";
	sTr+="<td  desc='desc' id='txtDesc'>&nbsp;</td>";
	sTr+="<td UoM='UoM'>&nbsp;</td>";
	sTr+="<td ><input type='text' cant='cant' name='a_InsumoCant["+CorrelaTivo+"]' size='5' class='number required' style='text-align:right' ></td>";
	sTr+="<td ><input type='text' name='a_PorcMerma["+CorrelaTivo+"]' size='5' class='number required' style='text-align:right' ></td>";
    sTr+="<td align='right'><img border='0' style='cursor:pointer' title='Eliminar Registro' src='/gourmet-express/trunk/imgs/icons/delete_icon.png' onclick='delete_TR_ItemCC(this)'></td>"; 		
    sTr+="</tr>";
    
    $("#mitablaCC tbody").append(sTr);
    
    loadAutocompleteItem(id_ItemCode);
    cantKeyupSum();
}

delete_TR_ItemCC = function (obj)
{
 $(obj).parents('tr').first().remove();
 cantSum();
 
}

cantKeyupSum = function()
{
  $("#mitablaCC tbody tr td input[cant='cant']").keyup(function(){

   cantSum();


  })
};

cantSum = function()
{

  var totMon=0;
  $("#mitablaCC tbody tr td input[cant='cant']").each(function() { 
            //add only if the value is number
            if(!isNaN($(this).val()) && $(this).val().length!=0) {
                totMon += parseFloat($(this).val());
            }          
  });
   totMon=totMon.toFixed(2); 
  $("#totMont").text(totMon);
  
};
</script>   
  <div id="module">    
	<h3>:: Edici�n de Recetas</h3>
	 <form id="form_editar" action="javascript: fn_actualizar();">
	   <input type="hidden" name="guardar" id="guardar" value="guardar"/>
			<table id="form">
				<tr>
					<td id="label">Receta Id</td><td><div><?php echo $o_rptaH->getRctRecetaId()?></div><input type="hidden" name="txtRecetaId" id="txtRecetaId" value="<?php echo $o_rptaH->getRctRecetaId()?>"  /></td>
				</tr>
				<tr>
					<td id="label" >Producto Id</td><td><input type="text" name="txtProductoId" id="txtProductoId" class='loadF21 val_ItemReceta' size="15" maxlength="15" value="<?php echo $o_rptaH->getRctProductoId()?>" /></td>
				</tr>
				<tr>
					<td id="label" >Descripci�n</td><td><div id='s_Descr'><?php echo $o_rptaH->getRctDescripcion()?></div><input type="hidden" name="txtDescripcion" id="txtDescripcion" size="35" value="<?php echo $o_rptaH->getRctDescripcion()?>" /></td>
				</tr>				
				<tr>
					<td id="label" >Tipo de Producto </td><td><div id='s_TipoProd'><?php echo $o_rptaH->getRctTipoProducto()?></div><input type="hidden" name="txtTipoDeProducto" id="txtTipoDeProducto" value="<?php echo $o_rptaH->getRctTipoProducto()?>" > </td>
				</tr>
				<tr>
					<td id="label" >UoM Producto </td><td><div id='s_UoM_Producto'><?php echo $o_rptaH->getRctProductoUoM()?></div><input type="hidden" name="txtUoM_Producto" id="txtUoM_Producto" value="<?php echo $o_rptaH->getRctProductoUoM()?>" ></td>
				</tr>
				<tr>
					<td id="label" >Cant de Producto </td><td><input type="text" name="txtCantProducto" id="txtCantProducto" size="5" maxlength="6" style="text-align:right" value="<?php echo $o_rptaH->getRctProductoCant()?>" /></td>
				</tr>
				<tr>
					<td id="label" >% Merma </td><td><input type="text" name="txtPorcMerma" id="txtPorcMerma" size="5" maxlength="6" style="text-align:right" class='number required' value='<?php echo $o_rptaH->getRctPorcMerma();?>' /></td>
				</tr>
				<tr>
					<td id="label" >Detalles</td><td><input type="text" name="txtDetalles" id="txtDetalles" size="35" value="<?php echo $o_rptaH->getRctDetalles()?>" /></td>
				</tr>
				<tr>
					<td id="label" >Observaciones</td><td>
                                            <textarea name="txtObservaciones" id="txtObservaciones" rows="3" cols="55"><?php echo $o_rptaH->getRctObservaciones()?></textarea>
                                        </td>
				</tr>                                
			</table>
			
			
			<table width="100%">
				<tr><td width="100%" align="right"><input type="button" value="Agregar Productos" onclick="add_TR_ItemCC()"><td></tr>
			</table>
			<table id='mitablaCC' width="100%" cellspacing="1">
                            <thead>
				<tr bgcolor="#CCCCCC">
					<td width="15%">Insumo Id</td>
					<td width="35%">Descripcion</td>
					<td width="10%">UoM</td>
					<td width="10%">Insumo Cant</td>
					<td width="10%">Porc Merma</td>
					<td width="20%"></td>
				</tr>
			    </thead>
                            <tbody>
				</tr><?php
				if(is_array($o_rptaH->get_oDetalleRecetaBean()))
				{
					$correlaTivo=1;
					foreach ($o_rptaH->get_oDetalleRecetaBean() as $key => $obj)
					{
						$id_ItemCode = "itemCode_".$correlaTivo;
						
						?>
    					<tr bgcolor='#FFFFFF'>
    						<td align='left'><input type='text' itemG='itemG' id='<?php echo $id_ItemCode;?>' name='a_InsumoId[<?php echo $correlaTivo;?>]' size='15' value="<?php echo $obj->getRcdInsumoId();?>"  style='width: 100px;' class='loadF2 required' ></td>
    						<td id='txtDesc' desc='desc' ><?php echo $obj->get_oDetalleItemBean()->getDescripcion();?></td>
    						<td align='left' UoM='UoM' ><?php echo $obj->get_oDetalleItemBean()->getUoM();?></td>
    						<td align='left'><input type='text' cant='cant' name='a_InsumoCant[<?php echo $correlaTivo;?>]' size='5' value="<?php echo $obj->getRcdInsumoCant();?>" class='number required' style='text-align:right'  ></td>
    						<td align='left'><input type='text' name='a_PorcMerma[<?php echo $correlaTivo;?>]' size='5' value="<?php echo $obj->getRcdPorcMerma();?>" class='number required' style='text-align:right'  ></td>
    						<td align='right'><img border='0' style='cursor:pointer' title='Eliminar Registro' src='/gourmet-express/trunk/imgs/icons/delete_icon.png' onclick='delete_TR_ItemCC(this)'></td>		
    					</tr>
    					 <script> loadAutocompleteItem('<?php echo $id_ItemCode; ?>'); CorrelaTivo=<?php echo $correlaTivo;?>;</script><?php
    					 $correlaTivo++;
					}
				}?>
                             </body>
                             <tfoot>
                                 <tr>
					<td colspan="3" bgcolor="#CCCCCC"><div align="right" >Total</div></td>
                                        <td colspan="1" bgcolor="#CCCCCC"><div align="right" id='totMont'></div></td>
                                        <td  colspan="2"></td>
                                 </tr>
                             </tfoot>
			</table>
			<br>	
			<table width="100%">
				<tr>
					<td width="90%" align="right"><input type="submit" name="guardar" value="Editar"></td>
					<td align="right"><input type="button" id="btn_cancelar"name="btn_cancelar" onclick="javascript: listarRecetasProduccion()" value="Cancelar"></td>
				<tr>	
			</table>
	  </form>
  </div>
    <script>
  $("#form_editar").validate();
  cantKeyupSum();
  cantSum();
  </script>
	<?php } ?>
	